package cn.wangxl.vertx.starter.core.eventBus;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.http.HttpServer;

/**
 * @Deacription TODO
 * @Author 20112128
 * @Date 2020/5/13 9:50
 **/
public class MyVerticle extends AbstractVerticle {

  private HttpServer server;

  @Override
  public void start(Future<Void> startFuture) throws Exception {
    server = vertx.createHttpServer().requestHandler(req -> {

      EventBus eventBus = vertx.eventBus();
      req.response()
        .putHeader("content-type", "text/plain")
        .end("Hello from Vert.x!");
    });

    // Now bind the server:
    server.listen(8080, res -> {
      if (res.succeeded()) {
        System.out.println("start success port 8080");
        startFuture.complete();
      } else {
        System.out.println("start fail port 8080");
        startFuture.fail(res.cause());
      }
    });
  }
}
